<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<head />

<ui:composition template="_template.xhtml">

	<ui:define name="conteudo">

		<p:panel id="panelPrincipal" header="Serviços">

			<p:commandButton
				actionListener="#{servicoBean.prepararAdicionarServico}"
				value="Novo" update=":formDialog:infosServico"
				oncomplete="PF('dialogGerServico').show();" />

			<h:form id="formServico">
				<p:dataTable id="tabelaServico" var="servico"
					value="#{servicoBean.listarServicos}">
					<p:column>
						<f:facet name="header">
							<h:outputText value="Nome" />
						</f:facet>
						<h:outputText value="#{servico.nome}" />
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Duração" />
						</f:facet>
						<h:outputText value="#{servico.duracao}" />
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Valor" />
						</f:facet>
						<h:outputText value="#{servico.valor}" />
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Genero" />
						</f:facet>
						<h:outputText value="" />
					</p:column>
					<p:column style="width: 200px; white-space: nowrap;">
						<f:facet name="header">
							<h:outputText value="Ações" />
						</f:facet>
						<p:commandButton
							actionListener="#{servicoBean.prepararAlterarServico}"
							value="Alterar" update=":formDialog:infosServico"
							oncomplete="PF('dialogGerServico').show();" />

						<p:commandButton
							actionListener="#{servicoBean.prepararExcluirServico}"
							oncomplete="PF('confirmDialogServico').show();" value="Excluir">
						</p:commandButton>

					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Produtos" />
						</f:facet>
						<p:commandButton
							actionListener="#{servicoBean.prepararExcluirServico}"
							oncomplete="PF('confirmDialogServico').show();" value="Produtos">
						</p:commandButton>

					</p:column>
				</p:dataTable>
			</h:form>
		</p:panel>

		<p:confirmDialog global="true" showEffect="fade"
			message="Deseja realmente excluir este serviço ?"
			header="Confirmação" widgetVar="confirmDialogServico">
			<p:commandButton value="Sim"
				actionListener="#{servicoBean.excluirServico}"
				action="servico.xhtml" update=":formServico:tabelaServico"
				oncomplete="PF('confirmDialogServico').hide();" />
			<p:commandButton value="Não"
				oncomplete="PF('confirmDialogServico').hide();" />
		</p:confirmDialog>

		<p:dialog header="Gerencia de Serviços" widgetVar="dialogGerServico"
			resizable="false" modal="true" showEffect="slide" width="500">
			<h:form id="formDialog">
				<h:panelGrid id="infosServico" columns="2"
					style="margin-bottom:10px">

					<h:outputLabel for="nome" value="Nome:" />
					<h:inputText id="nome" value="#{servicoBean.servico.nome}" />

					<h:outputLabel for="duracao" value="Duracao:" />
					<h:inputText id="duracao" value="#{servicoBean.servico.duracao}" />

					<h:outputLabel for="valor" value="Valor:" />
					<h:inputText id="valor" value="#{servicoBean.servico.valor}" />

					<p:commandButton
						actionListener="#{servicoBean.alterarOuInserirServico}"
						action="servico.xhtml" value="Salvar"
						update=":formServico:tabelaServico"
						oncomplete="PF('dialogGerServico').hide();" />

					<p:commandButton value="Cancelar"
						oncomplete="PF('dialogGerServico').hide();" />

				</h:panelGrid>
			</h:form>
		</p:dialog>

	</ui:define>
</ui:composition>
</html>